package Underworld_Survival;

import java.util.Map;
import java.util.function.Consumer;

abstract class OtherItem extends Item{
    private transient Consumer<Role> effect; // 关键：使用 Consumer 定义效果

    public OtherItem(String itemName, String itemIntroduction, String itemEffect,
                CurrencyType purchaseCurrency, int priceOfPurchaseItem,
                int priceOfSellingItem, Consumer<Role> effect){
        super(itemName,itemIntroduction,itemEffect,purchaseCurrency,priceOfPurchaseItem,priceOfSellingItem);
        this.effect=effect;
    }

    // 触发道具效果
    public void applyOtherItemEffect(Role role) {
        effect.accept(role);
    }

}

//全局道具

//1.仙丹elixir
class elixir extends OtherItem{
    public elixir(){
        super("{仙丹}","由炼药大师炼化而来，让自身基础属性得到突破，快速增强实力",
                "力量+2 速度+1 防御+1",CurrencyType.GOLD,120, 60,
                role->{role.modifyAttributes(Map.of(AttributeType.BASE_STR,2f,
                        AttributeType.BASE_DEF,1f,AttributeType.BASE_EP,1f),true);
                }
        );}

    @Override
    public String getItemId() { return "otherItem_elixir"; }

}
//2.金苹果goldenApple
class goldenApple extends OtherItem{
    public goldenApple(){
        super("{金苹果}","大自然孕育来的神奇苹果，吃了竟能提升体质！",
        "血量上限+10  能量上限+5",CurrencyType.GOLD,100, 50,
                role->{if(role instanceof Player){
                        role.modifyAttributes(Map.of(AttributeType.BASE_MAXHP,10f,
                                AttributeType.BASE_MAXAGI,5f),true);
                    }else{
                        role.modifyAttributes(Map.of(AttributeType.BASE_MAXHP,10f),true);
                    }
                }
        );}

    @Override
    public String getItemId() { return "otherItem_goldenApple"; }

}
//3.回生药resurrectionMedicine
class resurrectionMedicine extends OtherItem{
    public resurrectionMedicine(){
        super("{回生药}","没人知道这药怎么来的，又是如何起作用的，听说能让人起死回生，都将信将疑",
                "复活死亡的人(主动使用将会满状态)",CurrencyType.DIAMOND,40, 100,
                role->{if(role instanceof Player){
                    role.refillHP(role.getTotalMaxHP());
                    ((Player) role).refillAgi(((Player) role).getTotalMaxAgi());
                }else{
                    role.refillHP(role.getTotalMaxHP());
                }}
        );
    }

    @Override
    public String getItemId() { return "otherItem_resurrectionMedicine"; }

}
//4.万能药panacea
class panacea extends OtherItem{
    public panacea(){
        super("{万能药}","无论伤病多棘手，都能让身体恢复如初",
                "清除负面buff",CurrencyType.GOLD,60, 30,
                role->{role.removeDebuff();}
        );
    }
    @Override
    public String getItemId() { return "otherItem_panacea"; }

}